package ssm.dao;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ssm.pojo.User;

public class UserDaoImplTest {

//    private SqlSessionFactory sqlSessionFactory;

    private ApplicationContext applicationContext;
    @Before
    public void setUp() throws Exception{
//        // mybatis配置文件
//        String resource = "mybatis/SqlMapConfig.xml";
//        // 得到配置文件流
//        InputStream inputStream = Resources.getResourceAsStream(resource);
//
//        // 创建会话工厂，传入mybatis的配置文件信息
//        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");




    }

    @Test
    public void testFindUserById() throws Exception {

//        //创建UserDao对象
//        UserDao userDao = new UserDaoImpl(sqlSessionFactory);
        UserDao userDao = applicationContext.getBean(UserDao.class);
        //调用UserDao方法
        User user = userDao.findUserById(1);

        System.out.println(user.getUsername());

    }

//    @Test
//    public void testFindUserByName() throws Exception {
//
//        //创建UserDao对象
//        UserDao userDao = new UserDaoImpl(sqlSessionFactory);
//        //调用UserDao方法
//        List<User> list = userDao.findUserByName("小明");
//
//        System.out.println(list.size());
//
//
//
//    }


}
